package com.niocholas.study.keyword.xfinally;

import lombok.extern.slf4j.Slf4j;

/**
 * @author ze.dong
 * @version 创建时间：2020/3/24
 */
@Slf4j
public class StudyFinally {

    public static void main(String[] args) {
        log.info("当finally代码块中有return对象时 return value from : {}", returnExistedInFinally());
        log.info("当finally代码块中修改对象但是没有return时 return value from : {}", returnNotExistedInFinally());
    }

    public static String returnExistedInFinally() {
        String result;
        try {
            result = "method body";
            return result;
        } finally {
            result = "finally";
            return result;
        }
    }

    public static String returnNotExistedInFinally() {
        String result;
        try {
            result = "method body";
            return result;
        } finally {
            result = "finally";
        }
    }

}
